#!/bin/sh

SERVICE_HOME=/data/springcloud-web
cd ${SERVICE_HOME}
LIB_DIR=${SERVICE_HOME}/lib
LOGS_DIR=${SERVICE_HOME}/logs
#JAVA_BIN=/usr/lib/jvm/java-8-sun/bin/
JAVA_BIN=/data/jdk1.8.0_172/bin/
ARCHIVE_SUFFIX=`date +%Y%m%d-%H%M`

JAVA_ARGS="-server -Xms512m -Xmx1024m -XX:NewSize=64m -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=78 -XX:ThreadStackSize=256 -Xloggc:${LOGS_DIR}/gc.log"

JAR_NAME=""
files=`ls -1 ${LIB_DIR}`
for file in ${files} ;do
	JAR_NAME=${LIB_DIR}/${file}
done
echo ${JAR_NAME}

mv ${LOGS_DIR}/spring.log ${LOGS_DIR}/spring.log.${ARCHIVE_SUFFIX} 
mv ${LOGS_DIR}/stderr.log ${LOGS_DIR}/stderr.log.${ARCHIVE_SUFFIX} 
mv ${LOGS_DIR}/gc.log ${LOGS_DIR}/gc.log.${ARCHIVE_SUFFIX} 



${JAVA_BIN}java ${JAVA_ARGS} -jar ${JAR_NAME} --spring.profiles.active=dev --spring.cloud.config.profile=prod 1>${LOGS_DIR}/spring.log  2>${LOGS_DIR}/stderr.log &

echo "ad es service service starting..."
